$(function(){
    
    var idRotina = $('#idRotina').val();
    jQuery("#gridExames").jqGrid({
        caption: "Exames",
        url: "intranet/rotina/exames/id/"+idRotina,
        datatype: "json",
        colNames:['Exame', 'Tipo Resultado', 'Metodologia', 'Kit Sorológico'],
        colModel:[
            {name:'nome', index:'nome', width:180, align:"center"},
            {name:'resultado', index: 'resultado', width: 110, align: 'center', search:false},
            {name:'metodologia', index:'metodologia', width:300, align:"center", search:false},
            {name:'kitSorologia', index:'kitSorologia', width:340, align:"center", search:false}
        ],
        //rowNum: 10,
        //rowList: [10,20,30,50,100],
        height: 100,
        width: 900,
        pager: '#navExames',
        sortname: "idExame",
        sortorder: "ASC",
        multiselect: false,
        viewrecords: true,
        scroll:true,
        onSelectRow: function(ids) {
            if(ids == null) {
                ids=0;
		if(jQuery("#gridAmostras").jqGrid('getGridParam','records') >0 )
		{
                    jQuery("#gridAmostras").jqGrid('setGridParam',{url:"intranet/rotina/amostras/idRotina/"+idRotina+"/idExame/"+ids,page:1})
                    .trigger('reloadGrid');
		}
            } else {
                jQuery("#gridAmostras").jqGrid('setGridParam',{url:"intranet/rotina/amostras/idRotina/"+idRotina+"/idExame/"+ids,page:1})
		.trigger('reloadGrid');			
            }
	}

    })
    .navGrid("#navExame",{edit: false,add: false,del: false,search: false,view: false,refresh: false})
});

$(function(){
    var idRotina = $('#idRotina').val();
    jQuery("#gridAmostras").jqGrid({
        height: 100,
        width: 900,
        url: 'intranet/rotina/amostras/idRotina/'+idRotina+'/idExame/'+0,
        datatype: "json", 
        colNames: ['Amostra', 'Inicial','Resposta', 'Valor 1', 'Valor 2'],
        colModel: [
            {name: 'idAmostra', index: 'idAmostra', width: 175, align: 'center'},
            {name: 'inicial', index: 'inicial', width: 110, align: 'center'},
            {name: 'resposta', index: 'resposta', width: 200, align: 'center'},
            {name: 'valor1', index: 'valor1', width: 220, align: 'center', search:false},
            {name: 'valor2', index: 'valor2', width: 220, align: 'center', search:false}
        ],
        pager: '#navAmostras', 
        sortname: 'idAmostra', 
        viewrecords: true,
        sortorder: "asc", 
        multiselect: false,
        scroll: true,
        caption:"Amostras" 
    }).navGrid('#navAmostras',{add:false,edit:false,del:false,search:false,view:false,refresh:false});
});

jQuery("#btnVoltar").click( function() {
    intranet.carregaModulo('intranet/Rotina/');
});